package siga.visao_financeiro;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import siga.banco.conexao;
import siga.visao.index;
import siga.visao.verErros;

public class movContasAlterarValor extends javax.swing.JDialog {
    public static String cod_pessoa,cod_matricula,cod_fase;

    public static boolean ConfirmaValor;
    public static boolean isConfirmaValor() {
        return ConfirmaValor;
    }
    public static void setConfirmaValor(boolean ConfirmaValor) {
        movContasAlterarValor.ConfirmaValor = ConfirmaValor;
    }
    public movContasAlterarValor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpValor = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfValor = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alterar Valor Bruto do Boleto");

        jpValor.setName("jpValor"); // NOI18N

        jLabel1.setText("Valor Bruto:");
        jLabel1.setName("jLabel1"); // NOI18N

        jtfValor.setName("jtfValor"); // NOI18N

        jButton1.setText("Confirmar");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpValorLayout = new javax.swing.GroupLayout(jpValor);
        jpValor.setLayout(jpValorLayout);
        jpValorLayout.setHorizontalGroup(
            jpValorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpValorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpValorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpValorLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpValorLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpValorLayout.setVerticalGroup(
            jpValorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpValorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpValorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpValorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpValor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpValor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        List codigo = new ArrayList();
        try {
            cod_matricula = (cod_matricula.equals(""))? "": " and cod_matricula like \""+cod_matricula+"%\" ";
            cod_fase = (cod_fase.equals(""))? "" : "and cod_fase="+cod_fase;
            conexao.Query("select codigo from fin_contas_mov_r where cod_emp=" + index.cod_emp + " and cod_pessoa=" + cod_pessoa + " and status=\"A Receber\" " + cod_matricula + cod_fase);
            while(conexao.rs.next()){
                codigo.add(conexao.rs.getString("codigo"));
            }
            double vlbruto = Double.parseDouble(jtfValor.getText().replace(',', '.'));
            for(int i=0;i<codigo.size();i++){
                conexao.stm.executeUpdate("update fin_contas_mov_r set valor_bruto="+vlbruto+" " +
                        "where cod_emp="+index.cod_emp+" and codigo="+codigo.get(i));
            }
            setConfirmaValor(true);
            dispose();
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jpValor;
    private javax.swing.JTextField jtfValor;
    // End of variables declaration//GEN-END:variables

}
